﻿using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace ClassicPassWd
{
    /// <summary>
    /// ReplacePasswd.xaml 的交互逻辑
    /// </summary>
    public partial class ReplacePasswd : UserControl
    {
        public ReplacePasswd()
        {
            InitializeComponent();
        }


        public void GetPassword(int spaceSize)
        {
            var str = BoxProclaim.Text.ToCharArray();
            Array.Reverse(str);
            Slider.Maximum = BoxProclaim.Text == "" ? 0 : BoxProclaim.Text.Length;

            BoxPassword.Text = "";
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < str.Length; i++)
            {
                stringBuilder.Append(str[i]);
                if (spaceSize != 0 && (i + 1) % (spaceSize) == 0)
                    stringBuilder.Append(' ');
            }

            BoxPassword.Text = stringBuilder.ToString();
        }

        private void Slider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            GetPassword((int)Slider.Value);
        }

        private void BoxProclaim_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            GetPassword((int)Slider.Value);
        }
    }
}